Added filter_table_by_query#894
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #894 +/- ##
==========================================
+ Coverage 92.20% 92.22% +0.01%
==========================================
Files 49 49
Lines 7572 7585 +13
==========================================
+ Hits 6982 6995 +13
Misses 590 590
🚀 New features to boost your workflow:
|
|
Hey @srivarra, thanks for the PR! Sorry for not getting to it earlier, last months have been a bit hectic with the PhD, but checking it now. Might incorporate a tutorial notebook given that people could be new to this way of writing queries, but in any case I am in favor of this kind of syntax. |
|
@melonora No worries, hope the PhD is going well! Sounds good I'll draft up a tutorial notebook and request a review when it's done. |
|
Awesome! |
|
@melonora Would the proper process be:
tyty |
|
@srivarra Just open a PR in scverse/spatialdata-notebooks:) As a title you can give it |
|
@srivarra getting back to this. The code raises an exception likely due to this PR: https://github.com/narwhals-dev/narwhals/pull/2985/changes#diff-a05a3e6be8017e9767b6ee214af34fb2425fd0e038e3881165c4a27fe180004dR194. Tracked here: srivarra/annsel#64 |
|
I added a fix for |
|
@LucaMarconato Thanks for your PR! I've made a new release |
|
Thanks again @srivarra, great PR, I love the ergonomics! I'll adjust some things in the notebook and merge that soon. |
|
@LucaMarconato Thank you for your contribution and helping it cross the finish line! |
Added filtering by a table query as discussed in #626. Added both a standalone function
sd.filter_table_by_queryand a methodsd.SpatialData.filter_table_by_query.Function signature
sd.filter_by_table_queryis the same, but instead ofself, you have to provide theSpatialDataobject of interest.What expressions can you use?
narwhals. As long as the method doesn't aggregate.>,>=,<,<=,==,is_in,contains,starts_with,ends_withwork.What parts can you filter on?
You can filter on the
obsandvarDataFrame attributes ofAnnData.You can filter on
obs_namesandvar_names. (usesan.obs_names, andan.var_namesinstead ofan.col)You can filter on the expression matrix
Xw.r.t layers as well.Some Examples
SpatialData Repr
For context here is what the table looks like:
AnnData object with n_obs × n_vars = 3309 × 36 obs: 'row_num', 'point', 'cell_id', 'X1', 'center_rowcoord', 'center_colcoord', 'cell_size', 'category', 'donor', 'Cluster', 'batch', 'library_id' uns: 'spatialdata_attrs' obsm: 'X_scanorama', 'X_umap', 'spatial'"21d7", and filtervar_nameswhere we have"ASCT2","ATP5A"and any marker that starts with "CD".Output
"0"and"1".Output
obs_nameswhich start with"9"Output
&operatorOutput
Output
Other things to note:
I added a more complex SpatialData for testing in
conftest.py. I do not know if this should be there or somewhere else, or if I should make better use of what's there currently.Notebook: Table Queries